<template>
  <div>
  <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 基础表格
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
   
  <el-table :data="tableData" stripe style="width: 100%">
    <el-table-column prop="orderNo" label="订单编号"/>
    <el-table-column prop="createTime" label="创建时间"/>
    <el-table-column :formatter="orderStatus" prop="orderStatus" label="订单状态" />
     <el-table-column prop="payType" :formatter="pay" label="支付方式" />
     <el-table-column prop="payTime" label="支付时间" />
     <el-table-column prop="shippingType" :formatter="shoptype" label="发货方式" />
     <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >修改</el-button
            >
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
  </el-table>
   </div>
</template>
<script>
import axios from "axios";

export default ({
    data() {
        return{
           tableData:[],
        }
    },
    mounted(){
        this.getData();
    },
    methods:{
orderStatus(row){
    if(row.orderStatus==1){
      return '已支付'
    }
    if(row.orderStatus==2){
      return '未支付'
    }
    if(row.orderStatus==3){
      return '已发货'
    }
    if(row.orderStatus==4){
      return '未发货'
    }
    if(row.orderStatus==5){
      return '待收货'
    }
    if(row.orderStatus==6){
      return '已收货'
    }
},
      pay(row){
        
          if(row.payType==1){
            return '在线支付'
          }
          else{
            return '货到付款'
          }
      },
      shoptype(row){
          if(row.shippingType==1){
             return '京东快递'
          } 
          else{
             return '顺丰快递'
          }
      },
        getData(){
         axios({
            url:"https://localhost:44310/api/app/addmin-oeder",
            method:"get",
          }).then((res)=>{
            console.log(res.data);
            this.tableData=res.data;
          });
        },
            handleDelete(index, row) {
            if (confirm("确认删除吗")) {
              console.log(row.id);
             axios({
                url:"https://localhost:44310/api/app/addmin-oeder?gu=" + row.id,
                method:"DELETE",
                })
                .then((res) => {
                  console.log(row.id);
                  //删除
                  if (res.status == 204) {
                    alert("删除成功");
                    this.getData();
                  } else {
                    alert("删除失败");
                  }
                });
            
              
            }
          
          },

            handleEdit(index, row) {
            console.log(index, row.id);
            sessionStorage.setItem("update", row.id);
            this.$router.push({ name: "UptOrder", params: { id: row.id } }); //跳转到修改页面
          },
    }
})
</script>
